from sqlalchemy import Column, Integer, ForeignKey, DateTime, UniqueConstraint
from sqlalchemy.sql import func
from .database import Base

class Friendship(Base):
    __tablename__ = "friendships"
    
    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, index=True, nullable=False)  # 主动添加者
    friend_id = Column(Integer, index=True, nullable=False)  # 被添加者
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    
    # 约束：避免重复添加好友（user_id和friend_id的组合唯一）
    __table_args__ = (
        UniqueConstraint("user_id", "friend_id", name="unique_friendship"),
    )
